package cc.picc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import lombok.Setter;

/**
 * @author lijinting01
 *
 */
@Configuration
public class ScheduledTaskConfig {

	@Setter(onMethod = @__(@Autowired))
	private QuotaPublisher quotaPublisher;

	@Setter(onMethod = @__(@Autowired))
	private QuotaConsumer quotaConsumer;

	@Scheduled(fixedRate = 5_000)
	public void provideQuota() {
		quotaPublisher.operate(QuotaBucketConfig.BUCKET_NAME);
	}

	/**
	 * 慢速消费者
	 */
	@Scheduled(initialDelay = 1000, fixedDelay = 500)
	public void consumeQuotaSlow() {
		quotaConsumer.operate(QuotaBucketConfig.BUCKET_NAME);
	}

	/**
	 * 一般消费者
	 */
	@Scheduled(fixedRate = 40)
	public void consumeQuotaFine() {
		quotaConsumer.operate(QuotaBucketConfig.BUCKET_NAME);
	}

	/**
	 * 快速消费者
	 */
	@Scheduled(fixedRate = 20)
	public void consumeQuotaFast() {
		quotaConsumer.operate(QuotaBucketConfig.BUCKET_NAME);
	}

}
